using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using DAL;
using Utility;

namespace BUS
{
    public class HinhAnh_BUS
    {
        public static void Insert(HinhAnh_DTO hinhAnh)
        {
            HinhAnh_DAL hinhAnhDAL = new HinhAnh_DAL();
            hinhAnhDAL.Insert(hinhAnh);
        }
        public static void Update(HinhAnh_DTO hinhAnh)
        {
            HinhAnh_DAL hinhAnhDAL = new HinhAnh_DAL();
            hinhAnhDAL.Update(hinhAnh);
        }
        
        public static void Delete(int iD)
        {
            HinhAnh_DAL hinhAnhDAL = new HinhAnh_DAL();
            hinhAnhDAL.Delete(iD);
        }
        public static void Delete_mhang(int mamh)
        {
            HinhAnh_DAL hinhAnhDAL = new HinhAnh_DAL();
            hinhAnhDAL.Delete_MATHANG(mamh);
        }
        public static tbHinhAnhCollection Get(string where, int pageindex, int pagesize,string orderby,string orderdirection, out int total)
        {
            HinhAnh_DAL hinhAnhDAL = new HinhAnh_DAL();
            return hinhAnhDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbHinhAnhCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            HinhAnh_DAL hinhAnhDAL = new HinhAnh_DAL();
            return hinhAnhDAL.Get(cri.Criter, 0, 0, tbHinhAnhColumns.MaHinh.ToString(), OrderDirection.ASC.ToString(), out total);
        }

        public static tbHinhAnhCollection GetByMaMH(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbHinhAnhColumns.MaMH.ToString(), Condition.EQUAL, iD);
            HinhAnh_DAL hinhAnhDAL = new HinhAnh_DAL();
            tbHinhAnhCollection hinhAnhCollection = hinhAnhDAL.Get(cri.Criter,
                0, 0, tbHinhAnhColumns.MaHinh.ToString(), OrderDirection.ASC.ToString(), out total);
            if (hinhAnhCollection.Count > 0)
                return hinhAnhCollection;
            return null;
        }
        public static HinhAnh_DTO GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbHinhAnhColumns.MaMH.ToString(), Condition.EQUAL, iD);
            HinhAnh_DAL hinhAnhDAL = new HinhAnh_DAL();
            tbHinhAnhCollection hinhAnhCollection = hinhAnhDAL.Get(cri.Criter,
                0, 0, tbHinhAnhColumns.MaHinh.ToString(), OrderDirection.ASC.ToString(), out total);
            if (hinhAnhCollection.Count > 0)
                return hinhAnhCollection[0];
            return null;
        }
        public static tbHinhAnhCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            HinhAnh_DAL hinhAnhDAL = new HinhAnh_DAL();
            return hinhAnhDAL.Get(cri.Criter, 1, number,
                tbHinhAnhColumns.MaHinh.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbHinhAnhCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            HinhAnh_DAL hinhAnhDAL = new HinhAnh_DAL();
            return hinhAnhDAL.Get(cri.Criter, 1, number,
                tbHinhAnhColumns.MaHinh.ToString(), OrderDirection.DESC.ToString(), out total);
        }
    }
}
